<div class="page" style="min-height: 500px;">
  <div class="page-container">
    <div class="container">
      <div class="row">
        <div class="span3">
          <h4 class="header">Groups</h4>
          <div class="sidebar">
            <ul class="col-nav span3">
              <li style="background-color: #EEE;"><a href="<?php echo base_url('groups/group_list/' . $selected_year); ?>"><i class="pull-right icon-cog"></i>Group list</a></li>
              <li><a href="<?php echo base_url('groups/group_members/' . $selected_year); ?>"><i class="pull-right icon-user"></i>Group members</a></li>
              <li><a href="<?php echo base_url('groups/group_events/' . $selected_year); ?>"><i class="pull-right icon-star"></i>Group events</a></li>
            </ul>
          </div>
        </div>
        <div class="span9">
          <div class="btn-group pull-right">
            <?php if ($this->is_comitte_member) { ?>
              <a title="<?php echo 'Can accessed by : @' . @implode(', @', $this->comitte_members); ?>" href="<?php echo base_url('groups_manage'); ?>" class="btn">Manage groups</a>
            <?php } ?>
            <button class="btn dropdown-toggle" data-toggle="dropdown"><i class="icon-calendar"></i>&nbsp;<?php echo $selected_year; ?>&nbsp;<span class="caret"></span></button>
            <ul class="dropdown-menu">
              <?php if (!empty($group_years)) { ?>
                <?php foreach ($group_years as $group_year) { ?>
                  <li>
                    <a href="<?php echo site_url('groups/group_list/' . $group_year['group_years']); ?>"><?php echo $group_year['group_years']; ?></a>
                  </li>
                <?php } ?>
              <?php } ?>
            </ul>
          </div>
          <h4 class="header">Group list : <?php echo $selected_year; ?></h4>
          <?php if ($selected_year < NOW_YEAR) { ?>
            <h5>Champions</h5>
            <?php $count = 1; ?>
            <?php if (!empty($top_groups)) { ?>
              <div id="group_ranking" align="center">
                <?php foreach ($top_groups as $top_group) { ?>
                  <a style="text-decoration: none; cursor: pointer; color: #555555;" href="<?php echo base_url('groups/group_members/' . $selected_year . '#G' . $top_group['group_id']); ?>">
                    <div class="panel">
                      <?php if ($count == 1) { ?>
                        <div class="top info">
                          <i class="no-star"></i>
                          <i class="no-star"></i>
                          <i class="no-star"></i>
                          <h6>1st</h6>
                        </div>
                      <?php } ?>
                      <?php if ($count == 2) { ?>
                        <div class="top danger">
                          <i class="no-star"></i>
                          <i class="no-star"></i>
                          <h6>2nd</h6>
                        </div>
                      <?php } ?>
                      <?php if ($count == 3) { ?>
                        <div class="top warning">
                          <i class="no-star"></i>
                          <h6>3rd</h6>
                        </div>
                      <?php } ?>
                      <div class="bottom">
                        <b style="word-break: break-all;"><?php echo mb_substr($top_group['group_name'], 0, 15); ?></b>
                        <h6><?php echo $top_group['group_score']; ?></h6>
                      </div>
                    </div>
                  </a>
                  <?php $count++; ?>
                <?php } ?>
              </div>
            <?php } else { ?>
              <div class="widget">
                No champions !
              </div>
            <?php } ?>
          <?php } ?>

          <h5>Overall statistics<span class="pull-right">Total Points : <?php echo $total_groups_score; ?></span></h5>
          <div class="widget">
            <table style="width:100%">
              <?php $count = 1; ?>
              <?php if (!empty($groups)) { ?>
                <?php foreach ($groups as $group) { ?>
                  <tr>
                    <td class="bar-label"><?php echo $group['group_name']; ?></td>
                    <td class="bar-percent"><?php echo $group['group_score']; ?> Points</td>
                    <td>
                      <div class="progress">
                        <?php $percentage = @round(($group['group_score'] / $total_groups_score) * 100); ?>
                        <div title="<?php echo $percentage . '%'; ?>" style="cursor: pointer; width: <?php echo $percentage . '%'; ?>" class="bar"></div>
                      </div>
                    </td>
                  </tr>
                  <?php $count++; ?>
                <?php } ?>
              <?php } else { ?>
                <tr>
                  No groups !
                </tr>
              <?php } ?>
            </table>
          </div>
          <h5>Event statistics</h5>
          <div class="widget">
            <table style="width:100%">
              <?php $count = 1; ?>
              <?php if (!empty($groups)) { ?>
                <?php foreach ($groups as $group) { ?>
                  <tr>
                    <td class="bar-label"><?php echo $group['group_name']; ?></td>
                    <?php $nums = array(); ?>
                    <?php if (!empty($group_events)) { ?>
                      <?php foreach ($group_events as $event) { ?>
                        <?php $get_event_result = get_event_result_details($event['group_event_id'], $group['group_id']); ?>
                        <?php if (!empty($get_event_result)) { ?>
                          <?php $point = (int) @round(($get_event_result['group_event_result_score'] / $event['group_event_max_score']) * 10); ?>
                          <?php if (!empty($point)) { ?>
                            <?php $nums[] = $point; ?>
                          <?php } else { ?>
                            <?php $nums[] = 1; ?>
                          <?php } ?>
                        <?php } ?>
                      <?php } ?>
                      <td>
                        <?php if (!empty($nums) && is_array($nums)) { ?>
                          <span class="pbar"><?php echo @implode(',', $nums); ?></span>
                        <?php } else { ?>
                          <span class="pbar">0</span>
                        <?php } ?>
                      </td>
                    <?php } ?>
                  </tr>
                  <?php $count++; ?>
                <?php } ?>
              <?php } else { ?>
                No events !
              <?php } ?>
            </table>
          </div>
          <?php if (!empty($last_accessed)) { ?>
            <span>Last updated by : <b>@<?php echo $last_accessed->user_name; ?></b> on <b><?php echo $last_accessed->date; ?></b></span>
          <?php } ?>
        </div>
      </div>
    </div>
  </div>
</div>

